<!--以下是集货页面-->
<header>
	<div class="a-bar">
		<a href="javascript:history.back()" class="a-back">
			<{t}>QIFA平台-集货<{/t}>
		</a>
		<div class="a-right">
		</div>
	</div>
</header>
<div class="full-padding">
	<div class="data-so">
		<{t}>集货地：<{/t}><select id="depot_type" name="depot_type" onchange="selectChange();">
		<option value="0"><{t}>Lublino<{/t}></option>
		<option value="1"><{t}>HY仓库<{/t}></option>
		<option value="2"><{t}>其他<{/t}></option>
	</select>
	</div>
	<!-- lublino -->

	<div id="js_lublino" style="display: block">
		<{if $data.0}>
		<form id="goodscollection-confirm-form" action="<{link app=b2c ctl=wap_goodscollection act=do_goodscollection_edit}>" method="post">
		<{foreach from=$data.0 key=key item=info }>
		<div class="mainmenu">
		<div class="collection-list">
			<div class="collection-data">
				<a href="#">
					<ins class="fr">
						<i class="iconfont">&#xe603;</i>
						<i class="iconfont jt-up">&#xe602;</i>
					</ins>
					<span class="num fr"><{$info.total_nums}><{t}>箱<{/t}></span>
					<span class="code fl"><{t}>Lublino<{/t}></span>
					<span class="brand fl"><{t}><{$info.english_all_name}><{/t}></span>
				</a>
			</div>
			<div class="collection-detail">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">

					<tr>
						<td colspan="4" style="padding-bottom:5px;">
							<div class="operations mr_5"  style="float:left;">
								<span class="lineall" style="margin-top:4px; margin-left:5px;"><input type="checkbox" class="all-selector" onclick="selectAll(this)"><label><{t}>全选<{/t}></label></span>
							</div>
                            <span class="confirm-batch"><input type="button" class="operations" value="<{t}>批量确认<{/t}>" onclick="javascript:(0);"></span>
                            <button class="trigger-btn" id="confirm_final" onclick="goods_confirm('final');" type="submit"><{t}>确认完成<{/t}></button>

						</td>
                    </tr>

					<!--以下为一个订单信息循环-->

					<{foreach from=$info.orders key=okey item=oitem}>
                    <tbody class="collections">
					<tr>
						<td colspan="4" class="collec-title"><{t}>订单：<{/t}><{$okey}></td>
					</tr>
					<{foreach from=$oitem key=dkey item=ditem}>
					<tr>
					  <td colspan="4"><table width="100%" border="0" cellspacing="0" cellpadding="0">
					    <tr>
					      <td><{$ditem.brand_name}></td>
					      <td align="right"><b><{$ditem.bn}></b></td>
				        </tr>
				      </table></td>
				  </tr>
					<tr>
						<td><input class="selector" type="checkbox" name="item[]" value="<{$ditem.obj_id}>" onclick="do_select();"></td>
						<td><span class="num2 js_quantity"><{$ditem.remain_num}></span></td>
						<td>
							<input type="text" size="5" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" id="con_num[<{$ditem.obj_id}>]" name="con_num[<{$ditem.obj_id}>]" class="putstyle3" rel="<{$ditem.obj_id}>" value="<{$ditem.gc_confirm_num}>" />
						</td>
						<td>
							<input type="hidden" name="mainOrder_id" value="<{$ditem.mainOrder_id}>"/>
							<input type="hidden" name="gc_id" value="<{$ditem.gc_id}>"/>
							<input type="hidden" id="opt" name="opt[]" value="">
							<{if $ditem.status==0}>
							<a href="<{link app=b2c ctl='wap_goodscollection' act='goCollect' arg=$ditem.obj_id arg1=$ditem.goods_id}>" class="btn-ope single_confirm fr"><{t}>OK<{/t}></a>
							<{else}>
							<a href="<{link app=b2c ctl='wap_goodscollection' act='goCollect' arg=$ditem.obj_id arg1=$ditem.goods_id}>" class="btn-ope2 single_confirm fr"><{t}>更改<{/t}></a>
							<{/if}>
						</td>
						<!--<td><input name="" type="button" class="btn-ope" value="OK"></td>-->
					</tr>
					<{/foreach}>
                    </tbody>
					<{/foreach}>


					<!--以上为一个订单信息循环-->

				</table>
			</div>
		</div>
			</div>
		<{/foreach}>
			</form>
	<{else}>
		<{t}>暂无数据<{/t}>
	<{/if}>
	</div>
	<!-- hy -->
	<div id="js_hy" style="display: none;">
		<{if $data.1}>
		<form id="goodscollection-confirm-form" action="<{link app=b2c ctl=wap_goodscollection act=do_goodscollection_edit}>" method="post">
		<{foreach from=$data.1 key=key1 item=info1 }>
		<div class="mainmenu">
		<div class="collection-list">
			<div class="collection-data">
				<a href="#">
					<ins class="fr">
						<i class="iconfont">&#xe603;</i>
						<i class="iconfont jt-up">&#xe602;</i>
					</ins>
					<span class="num fr"><{$info1.total_nums}><{t}>箱<{/t}></span>
					<span class="code fl"><{t}>HY仓库<{/t}></span>
					<span class="brand fl"><{t}><{$info1.english_all_name}><{/t}></span>
				</a>
			</div>
			<div class="collection-detail">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">

					<tr>
						<td colspan="4" style="padding-bottom:5px;">
							<div class="operations mr_5" style="float:left;">
								<span class="lineall" style="margin-top:4px; margin-left:5px;"><input type="checkbox" class="all-selector" onclick="selectAll(this)"><label><{t}>全选<{/t}></label></span>
                           </div>
							<span class="confirm-batch"><input type="button" class="operations" value="<{t}>批量确认<{/t}>" onclick="javascript:(0);"></span>
							<button class="trigger-btn" id="confirm_final" onclick="goods_confirm('final');" type="submit"><{t}>确认完成<{/t}></button>

						</td>
					</tr>

					<!--以下为一个订单信息循环-->

					<{foreach from=$info1.orders key=okey1 item=oitem1}>
                    <tbody class="collections">
					<tr>
						<td colspan="4" class="collec-title"><{t}>订单：<{/t}><{$okey1}></td>
					</tr>
					<{foreach from=$oitem1 key=dkey1 item=ditem1}>
                    <tr>
                    <td colspan="4">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
					    <tr>
					      <td><{$ditem1.brand_name}></td>
					      <td align="right"><b><{$ditem1.bn}></b></td>
				        </tr>
				      </table>
                    </td>
                    </tr>

					<tr>
						<td><input class="selector" type="checkbox" name="item[]" value="<{$ditem1.obj_id}>" onclick="do_select();"></td>
						<td><span class="num2 js_quantity"><{$ditem1.remain_num}></span></td>
						<td>
							<input type="text" size="5" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" id="con_num[<{$ditem1.obj_id}>]" name="con_num[<{$ditem1.obj_id}>]" class="putstyle3" rel="<{$ditem1.obj_id}>" value="<{$ditem1.gc_confirm_num}>" />
						</td>
						<td>
							<input type="hidden" name="mainOrder_id" value="<{$ditem1.mainOrder_id}>"/>
							<input type="hidden" name="gc_id" value="<{$ditem1.gc_id}>"/>
							<input type="hidden" id="opt" name="opt[]" value="">
							<{if $ditem1.status==0}>
							<a href="<{link app=b2c ctl='wap_goodscollection' act='goCollect' arg=$ditem1.obj_id arg1=$ditem1.goods_id}>" class="btn-ope single_confirm fr"><{t}>OK<{/t}></a>
							<{else}>
							<a href="<{link app=b2c ctl='wap_goodscollection' act='goCollect' arg=$ditem1.obj_id arg1=$ditem1.goods_id}>" class="btn-ope2 single_confirm fr"><{t}>更改<{/t}></a>
							<{/if}>
						</td>
						<!--<td><input name="" type="button" class="btn-ope" value="OK"></td>-->
					</tr>
					<{/foreach}>
                    </tbody>
					<{/foreach}>

					<!--以上为一个订单信息循环-->
				</table>
			</div>
		</div>
			</div>
		<{/foreach}>
		</form>
	<{else}>
		<{t}>暂无数据<{/t}>
	<{/if}>
	</div>
	<!-- 其他 -->
	<div id="js_qt" style="display: none;">
		<{if $data.2}>
		<form id="goodscollection-confirm-form" action="<{link app=b2c ctl=wap_goodscollection act=do_goodscollection_edit}>" method="post">
		<{foreach from=$data.2 key=key2 item=info2 }>
		<div class="mainmenu">
		<div class="collection-list">
			<div class="collection-data">
				<a href="#">
					<ins class="fr">
						<i class="iconfont">&#xe603;</i>
						<i class="iconfont jt-up">&#xe602;</i>
					</ins>
					<span class="num fr"><{$info2.total_nums}><{t}>箱<{/t}></span>
					<span class="code fl"><{t}>其他仓库<{/t}></span>
					<span class="brand fl"><{t}><{$info2.english_all_name}><{/t}></span>
				</a>
			</div>

			<div class="collection-detail">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">

					<tr>
						<td colspan="4" style="padding-bottom:5px;">
							<div class="operations mr_5" style="float:left;">
								<span class="lineall" style="margin-top:4px; margin-left:5px;"><input type="checkbox" class="all-selector" onclick="selectAll(this)"><label><{t}>全选<{/t}></label></span>
                            </div>
							<span class="confirm-batch"><input type="button" class="operations" value="<{t}>批量确认<{/t}>" onclick="javascript:(0);"></span>
							<button class="trigger-btn" id="confirm_final" onclick="goods_confirm('final');" type="submit"><{t}>确认完成<{/t}></button>
						</td>
					</tr>

					<{foreach from=$info2.orders key=okey2 item=oitem2}>
                    <tbody class="collections">
					<tr>
						<td colspan="4" class="collec-title"><{t}>订单：<{/t}><{$okey2}></td>
					</tr>
					<{foreach from=$oitem2 key=dkey2 item=ditem2}>

                    <tr>
                    <td colspan="4">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
					    <tr>
					      <td><{$ditem2.brand_name}></td>
					      <td align="right"><b><{$ditem2.bn}></b></td>
				        </tr>
				      </table>
                    </td>
                    </tr>
					<tr id="">
						<td><input class="selector" type="checkbox" name="item[]" value="<{$ditem2.obj_id}>" onclick="do_select();"></td>
						<td><span class="num2 js_quantity"><{$ditem2.remain_num}></span></td>
						<td>
							<input type="text" size="5" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" id="con_num[<{$ditem2.obj_id}>]" name="con_num[<{$ditem2.obj_id}>]" class="putstyle3" rel="<{$ditem2.obj_id}>" value="<{$ditem2.gc_confirm_num}>" />
						</td>
						<td>
							<input type="hidden" name="mainOrder_id" value="<{$ditem2.mainOrder_id}>"/>
							<input type="hidden" name="gc_id" value="<{$ditem2.gc_id}>"/>
							<input type="hidden" id="opt" name="opt[]" value="">
							<{if $ditem2.status==0}>
							<a href="<{link app=b2c ctl='wap_goodscollection' act='goCollect' arg=$ditem2.obj_id arg1=$ditem2.goods_id}>" class="btn-ope single_confirm fr"><{t}>OK<{/t}></a>
							<{else}>
							<a href="<{link app=b2c ctl='wap_goodscollection' act='goCollect' arg=$ditem2.obj_id arg1=$ditem2.goods_id}>" class="btn-ope2 single_confirm fr"><{t}>更改<{/t}></a>
							<{/if}>
						</td>
						<!--<td><input name="" type="button" class="btn-ope" value="OK"></td>-->
					</tr>
					<{/foreach}>
                    </tbody>
					<{/foreach}>

					<!--以上为一个订单信息循环-->
				</table>
			</div>

		</div>
			</div>
		<{/foreach}>
			</form>
		<{else}>
			<{t}>暂无数据<{/t}>
		<{/if}>
	</div>

</div>

<script>

	$(document).ready( function() {
		var collectionlist = $('.collection-data');
		collectionlist.on('click',function() {
			$(this).parent('.collection-list').children('.collection-detail').toggle().toggleClass('current').parent('.collection-list').toggleClass('current').siblings('.collection-list').removeClass('current').children('.collection-detail').hide();
		});
	});

	$('.single_confirm').on('click',function(e){
		e.preventDefault();
		var self = this;
		var input = $(this).parents('tr').find('.putstyle3');
		var num = input.val();
		var quantity = $(this).parents('tr').find('.js_quantity').html();
		var gc_id = $(this).parents('tr').find('input[name=gc_id]').val();
		var mainOrder_id = $(this).parents('tr').find('input[name=mainOrder_id]').val();
		var postdata = 'con_num=' + num + '&mainOrder_id=' + mainOrder_id + '&gc_id=' + gc_id;

		if(num && num >= 0){
			if(num > quantity){
				//var tips = new Tips(input);
				//tips.show('<{t}>实际集货数量不大于计划数量！<{/t}>');
				alert('<{t}>实际集货数量不大于计划数量！<{/t}>');
				return false;
			}
			$.post($(this).attr('href'), postdata, function(re) {
				try{
					rs = $.parseJSON(re);
				} catch (e) {}
				if(rs.error) {
					if(typeof rs.error === 'string') alert(rs.error);
				}
				if(typeof rs.success === 'string') alert(rs.success);
				window.reload();
			});

		}else{
			//var tips = new Tips(input);
			//tips.show('<{t}>实际集货数不能小于0！<{/t}>');
			alert('<{t}>实际集货数不能小于0！<{/t}>');
			return false;
		}
	});



	function selectChange(){
		var depot_type=document.getElementById("depot_type").value;
		var lublino = document.getElementById("js_lublino");
		var hy = document.getElementById("js_hy");
		var qt = document.getElementById("js_qt");
		if( depot_type == 0 ){
			lublino.style.display='block';
			hy.style.display='none';
			qt.style.display='none';

		}
		if( depot_type == 1 ){
			lublino.style.display='none';
			hy.style.display='block';
			qt.style.display='none';
		}
		if( depot_type == 2 ){
			lublino.style.display='none';
			hy.style.display='none';
			qt.style.display='block';
		}

	}

	//获取选中商品
	function show(){
		var cBox = document.getElementsByName("item[]");
		var idents = new Array();
		for(i = 0;i < cBox.length;i++){
			if(cBox[i].checked){
				idents.push(cBox[i].checked);
			}
		}
		return idents;
	}

	function do_select(){
		if(show().length==0){
			no_checked();
		}else{
			has_checked();
		}
	}

	//选中商品的状态为黄色
	function has_checked(){
		ul = '<input type="submit" class="operations" value="<{t}>批量确认<{/t}>" style="background-color:#f18007;border:0;color:white;padding:6px 8px 7px 8px;">';
		$('#goodscollection-confirm-form .confirm-batch').html(ul);
	}

	//不选中时为灰色
	function no_checked(){
		ul = '<input type="button" class="operations" value="<{t}>批量确认<{/t}>" style="background-color:gray;border:0;color:white;padding:6px 8px 7px 8px;" onclick="javascript:(0);">';
		$('#goodscollection-confirm-form .confirm-batch').html(ul);
	}

	//全选
	function selectAll(){
		var arr = document.getElementsByName("item[]");
		var is_checked = arr[0].checked;
		for(var i = 0;i < arr.length;i++){
			if(is_checked){
				arr[i].checked = false;
			}else{
				arr[i].checked = true;
			}
		}
		if(is_checked){
			no_checked();
		}else{
			has_checked();
		}
	}

	function isSelected(){
		item = document.getElementsByName("item[]");
		if(!item) return false;
		for(i=0;i<item.length;i++){
			if(item[i].checked){
				return true;
			}
		}
		all = document.getElementsByClassName("all-selector");
		if(!all) return false;
		for(i=0;i<all.length;i++){
			if(all[i].checked){
				return true;
			}
		}
		return false;
	}

	function goods_confirm(opt){
		//if(opt != 'final' && !isSelected()){
		if( !isSelected()){
			//alert('<{t}>请选择商品！<{/t}>');
			return false;
		}
		$('#opt').val(opt);

		/*var cBox = document.getElementsByName("item[]");
		for(i = 0;i < cBox.length;i++){
			if(cBox[i].checked){
				var input = document.getElementById("con_num["+cBox[i].value+"]");
				var num = input.value;
				var quantity = $($(input).parents('td')[0]).prev('td').find('.js_quantity').html();

				if(!(num && num >= 0)){
					alert('<{t}>实际集货数不能小于0！<{/t}>');
					return false;
				}
				if(num > quantity){
					alert('<{t}>实际集货数量不大于计划数量！<{/t}>');
					return false;
				}
			}
		}*/

		/*if(opt == 'final')
		{
			alert('<{t}>是否确认完成？<{/t}>');
		}*/

		$('#goodscollection-confirm-form').submit();
	}



</script>